<?php
namespace app\index\controller;
use caretree\Caretree;
class Cate extends Base
{
    public function index($id)
    {
		//获取当前栏目及其子栏目的id，返回数组
			$cateTree = new Caretree();
			$ids = $cateTree->childrenids($id,db('cate'));
			//获得该id下的所有子id
			$ids[] = $id;//把自己放进去
			$map['cate_id']=array('IN',$ids);//拼装查询条件
			
			$cacheArtResName = $id.'_artRes';
			if(cache($cacheArtResName)){
				$artRes=cache($cacheArtResName);
			}else{
				$artRes = db('article')->where($map)->select();//查询栏目下的所有文章
				cache($cacheArtResName,$artRes,3600);
			}
			//当前栏目的基本信息
			$cates = db('cate')->find($id);
			//普通栏目分类
			if(cache('comCates')){
				$comCates=cache('comCates');
			}else{
				$comCates = model('cate')->getComCates();
				cache('comCates',$comCates,3600);
			}
			
			//帮助左侧栏目分类
			if(cache('shopHelpCates')){
				$shopHelpCates=cache('shopHelpCates');
			}else{
				$shopHelpCates=model('cate')->shopHelpCates();
				cache('shopHelpCates',$shopHelpCates,3600);
			}
	// dump($comCates);die;
	$this->assign([
		'show_right' => 1, //文章列表和商品列表头部偏移判断
		'comCates'  => $comCates,
		'shopHelpCates'=>$shopHelpCates,
		'artRes' =>$artRes, //当前栏目及其子栏目里的文章
		'cates'=>$cates,//当前栏目的基本信息
	]);
	return view('cate');
   }
}
